home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
examples
/
libpod
/
logit.c.z
/
logit.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
4KB
|
135 lines
/**************************************************************************
*
* Copyright (c) 1992 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: logit.c
*
* Description: Sample program that demonstrates the use of the local
* libpod log file write function.
*
* Usage: logit [-j job_id] [-u username]
* printer_name start|end|{msg_code}
*
* The message parameter specified on the command-line determines
* the standard message that will be written to the log file.
*
* start - prints a standard print job start message in the log file
* end - prints a standard print job end message in the log file
* msg_code - any valid message code number. Code numbers can be
* specified in decimal, hex or octal.
*
* Note: you must have root or lp permission to successfully run this
* program.
*
**************************************************************************/
#ident "$Revision: 1.1 $"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <pod.h>
#define HANDLE_ERROR(pname) { \
PDPerror(pname); \
exit(1); \
}
void usage(char*);
int main(int argc, char **argv)
{
int ch, msg_code;
char *job_id = NULL;
char *username = NULL;
char *msg_code_str, *printer_name;
PDMessageStruct msg;
/*
* Get command line switches
*/
while ((ch = getopt(argc, argv, "j:u:")) != -1) {
switch (ch) {
case 'j':
job_id = optarg;
break;
case 'u':
username = optarg;
break;
case '?':
default:
usage(argv[0]);
exit(1);
}
}
/*
* Get printer name and message code from command-line
*/
if (argc < optind + 2) {
usage(argv[0]);
exit(1);
}
printer_name = argv[optind];
msg_code_str = argv[optind+1];
if (!strcasecmp(msg_code_str, "start"))
msg_code = PD_INFO_JOB_START;
else if (!strcasecmp(msg_code_str, "end"))
msg_code = PD_INFO_JOB_END;
else {
if ((msg_code = strtol(msg_code_str, (char**)NULL, 0)) == 0) {
(void)fprintf(stderr, "Invalid message code: %s\n",
msg_code_str);
exit(1);
}
}
/*
* Construct a standard message based on the message code
*/
if (PDMakeMessage(&msg, msg_code) < 0)
HANDLE_ERROR(argv[0]);
/*
* Write the log entry
*/
if (PDLocalWriteLog(printer_name, job_id, username, &msg) < 0)
HANDLE_ERROR(argv[0]);
return 0;
}
void usage(char *progname)
{
(void)fprintf(stderr, "Usage: %s [-j job_id] [-u username] ", progname);
(void)fprintf(stderr, "printer_name start | end | {msg_code}\n");
}